
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for send_message.
	''' </summary>
	Public Partial Class send_message
		Inherits BaseWebPage
		Protected hlChooseFriend As System.Web.UI.WebControls.HyperLink
		Protected lblNoFriends As System.Web.UI.WebControls.Label
		Private action As Integer = -1
		Protected hlGroupBulletin As System.Web.UI.WebControls.HyperLink
		Protected hlGroupBlog As System.Web.UI.WebControls.HyperLink
		Protected hlGroupTrash As System.Web.UI.WebControls.HyperLink


		Private bIsGroupBulletin As Boolean = False
		Private msgID As Integer
		Private usrID As Integer = -1
		Private grpID As Integer = -1
		Private grp As Group = Nothing
		Private isGroupMode As Boolean = False
		Private msgType As Integer = -1
		Protected isUserMode As Boolean = False
		' true - prev page is user messages, false - prev page is group messages
		Protected htPageConstants As New Hashtable()

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			' this.pageTemplate.PageTitle = PageTitles.SEND_MESSAGE_PAGE;
			Dim usr As User = LoggedUser

			If usr = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If
			'Response.Redirect(Constants.LOGIN_PAGE);	

			If Request.Params("action") <> Nothing Then
				action = Convert.ToInt32(Request.Params("action"))
			End If

			Me.initPageTitles(Constants.SEND_MESSAGE, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			' init tabs
			ucTabs.ActiveTab = 0
			ucTabs.PageName = Constants.SEND_MESSAGE
			grpBlogTabs.ActiveTab = 0
			grpBlogTabs.PageName = Constants.SEND_MESSAGE

			grpBlogTabs.Visible = False

			' throw exceptions if any of the mandatory parameters is not provided
			Select Case action
				Case Constants.MESSAGE_REPLY_ACTION
					If Request.Params("id") = Nothing OrElse Request.Params("id") = "" OrElse Request.Params("uid") = Nothing OrElse Request.Params("uid") = "" Then
						Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
					End If
					Exit Select
				Case Constants.MESSAGE_FORWARD_ACTION
					If Request.Params("id") = Nothing OrElse Request.Params("id") = "" Then
						Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
					End If
					Exit Select
				Case Constants.MESSAGE_FORWARD_A_FRIEND_ACTION
					If Request.Params(Constants.FORWARD_A_FRIEND_PARAM) = Nothing OrElse Request.Params(Constants.FORWARD_A_FRIEND_PARAM) = "" Then
						Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
					End If
					Exit Select
				Case Constants.MESSAGE_RECOMMEND_ACTION
					If Request.Params(Constants.RECOMMENDED_USER_PARAM) = Nothing OrElse Request.Params(Constants.RECOMMENDED_USER_PARAM) = "" OrElse Request.Params(Constants.RECOMMENDED_TO_USER_PARAM) = Nothing OrElse Request.Params(Constants.RECOMMENDED_TO_USER_PARAM) = "" Then
						Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
					End If
					Exit Select
				Case Constants.MESSAGE_FORWARD_A_GROUP_ACTION
					If Request.Params(Constants.FORWARD_A_GROUP_PARAM) = Nothing OrElse Request.Params(Constants.FORWARD_A_GROUP_PARAM) = "" Then
						Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
					End If
					Exit Select
				Case Constants.MESSAGE_TO_GROUP_ACTION
					If Request.Params(Constants.GROUP_PARAM) = Nothing OrElse Request.Params(Constants.GROUP_PARAM) = "" Then
						Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
					End If
					Exit Select
			End Select

			If Request.Params(Constants.USER_MODE_PARAM) <> Nothing AndAlso Request.Params(Constants.USER_MODE_PARAM) = "true" Then
				isUserMode = True
			End If

			If Request.Params(Constants.GROUP_PARAM) <> Nothing AndAlso Request.Params(Constants.GROUP_PARAM) <> "" Then
				Try
					grpID = Convert.ToInt32(Request.Params(Constants.GROUP_PARAM))
				Catch
					Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
				End Try
				grp = Groups.GetGroupByID(grpID)
				If grp = Nothing Then
					Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
				End If

				isGroupMode = True
			End If

			If isGroupMode AndAlso Not isUserMode Then
				grpBlogTabs.Visible = True
				ucTabs.Visible = False
				'hlBackToInbox.NavigateUrl = "../" + Constants.BULLETIN + "?" + Constants.GROUP_PARAM + "=" + grp.ID;
				'hlBackToInbox.Text = this.GetPageConstText(htPageConstants, "CONST_GroupReturnMessages_TEXT");
				'hlGroupBulletin.NavigateUrl = "../" + Constants.BULLETIN + "?" + Constants.GROUP_PARAM + "=" + grp.ID;
				'hlGroupBlog.NavigateUrl = "../" + Constants.BLOG + "?" + Constants.GROUP_PARAM + "=" + grp.ID;
				'hlGroupTrash.NavigateUrl = "../" + Constants.TRASH + "?" + Constants.GROUP_PARAM + "=" + grp.ID;
				hlBackToGroup.NavigateUrl = "../" + Constants.GROUP_WELCOME + "?" + Constants.GROUP_PARAM + "=" + grpID
				hlBackToGroup.Text = (Me.GetPageConstText(htPageConstants, "CONST_GroupBackLink_TEXT")).Replace("[PARAM]", grp.Name)
			End If

			'			if ( action == Constants.MESSAGE_TO_GROUP_ACTION )
			'			{
			'				if ( !isGroupMode )
			'					throw new Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS);

			'				litMainPageTitle.Text = this.GetPageConstText(htPageConstants, "CONST_GroupTitle_TEXT");
			'				hlGroupBulletin.NavigateUrl = "../" + Constants.BULLETIN + "?" + Constants.GROUP_PARAM + "=" + grpID;
			'				hlGroupBlog.NavigateUrl = "../" + Constants.BLOG + "?" + Constants.GROUP_PARAM + "=" + grpID;
			'			}

			' limit textarea
			txtMessage_bulletin.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MESSAGES_MAX_CHARS.ToString()))
			txtMessage_bulletin.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MESSAGES_MAX_CHARS.ToString()))

			' init direct friends list
			Dim dfList As UsersFriends = Me.LoggedUser.DirectFriends
			Dim dfCount As Integer = dfList.Count

			'if(dfCount == 0)
			'{
			'	lblNoFriends.Visible = true;
			'	lblTo.Visible = false;
			'	lblSubject.Visible = false;
			'	lblMessage.Visible = false;
			'	txtSubject_bulletin.Visible = false;
			'	txtMessage_bulletin.Visible = false;
			'	btn_send_bulletin.Visible = false;
			'}
			'else
			'{
			If action = Constants.MESSAGE_FORWARD_ACTION OrElse action = Constants.MESSAGE_FORWARD_A_FRIEND_ACTION OrElse action = Constants.MESSAGE_FORWARD_A_GROUP_ACTION Then
				ddlDirectFriends.Visible = True

				Dim arrFriends As New ArrayList()
				Dim tmpArray As ArrayList

				For Each df As DirectFriend In dfList
					tmpArray = New ArrayList()
					tmpArray.Add(df.[Friend].ID)
					tmpArray.Add(df.[Friend].Name + " " + df.[Friend].LastName)
					arrFriends.Add(tmpArray)
				Next

				arrFriends.Sort(New CompareDirectFriends(CompareField.Name))

				If Not Me.IsPostBack Then
					Dim tmpLI As ListItem
					Dim i As Integer = 0
					i = 0
					While i < arrFriends.Count
						tmpArray = DirectCast(arrFriends(i), ArrayList)
						tmpLI = New ListItem(tmpArray(1).ToString(), tmpArray(0).ToString())
						ddlDirectFriends.Items.Add(tmpLI)
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
				End If
			End If
			'}


			' check user
			If Request.Params("uid") <> Nothing Then
				usrID = Convert.ToInt32(Request.Params("uid"))
				Dim userIDToSend As Integer = usrID


				' check if the recipient is the logged user

				If userIDToSend = LoggedUser.ID Then
					lblSendYourselfMessage.Visible = True
					HideAllFields()
				Else
					' check if the recipient is direct friend is removed on 12.09.2004
					'if(usr.DirectFriends.Contains(userIDToSend))
					'{
					Dim toUser As User = Users.GetUserByID(userIDToSend)
					hlToName.NavigateUrl = "../" + Constants.MEMBERS + "?id=" + userIDToSend
					hlToName.Text = Me.getBeginning(HttpUtility.HtmlEncode(toUser.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
					hlToName.Visible = True

					If toUser.DefaultPicture <> Nothing Then
						hlToPhoto.ImageUrl = Pictures.GetPictureSrcFullURL(toUser.DefaultPicture, True, "../")
						hlToPhoto.NavigateUrl = "../" + Constants.MEMBERS + "?id=" + userIDToSend
						hlToPhoto.ToolTip = toUser.Name
						hlToPhoto.Visible = True
					Else
						hlToPhoto.Visible = False
					End If

					' show secomd user if the action is "Recommend a match"
					If action = Constants.MESSAGE_RECOMMEND_ACTION Then
						Dim userIDToSend2 As Integer = Convert.ToInt32(Request.Params(Constants.RECOMMENDED_USER_PARAM))

						Dim toUser2 As User = Users.GetUserByID(userIDToSend2)

						hlTo2Name.NavigateUrl = "../" + Constants.MEMBERS + "?id=" + userIDToSend2
						hlTo2Name.Text = Me.getBeginning(HttpUtility.HtmlEncode(toUser2.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
						hlTo2Name.Visible = True

						If toUser2.DefaultPicture <> Nothing Then
							hlTo2Photo.ImageUrl = Pictures.GetPictureSrcFullURL(toUser2.DefaultPicture, True, "../")
							hlTo2Photo.NavigateUrl = "../" + Constants.MEMBERS + "?id=" + userIDToSend2
							hlTo2Photo.ToolTip = toUser2.Name
							hlTo2Photo.Visible = True
						Else
							hlTo2Photo.Visible = False
						End If
						'}
						'else
						'{
						'	Response.Redirect(Constants.ERROR_PAGE + "?e=" + Constants.ERROR_NO_DIRECT_FRIEND, true);
						'}
					End If
				End If
ElseIf action = Constants.MESSAGE_FORWARD_ACTION OrElse action = Constants.MESSAGE_FORWARD_A_FRIEND_ACTION OrElse action = Constants.MESSAGE_FORWARD_A_GROUP_ACTION Then
				ddlDirectFriends.Visible = True

				hlToName.Visible = False
				hlToPhoto.Visible = False
				'if (action == Constants.MESSAGE_FORWARD_A_FRIEND_ACTION || action == Constants.MESSAGE_FORWARD_A_GROUP_ACTION)
				tblToUsers.Visible = False
ElseIf action = Constants.MESSAGE_TO_GROUP_ACTION Then
				If Not isGroupMode Then
					Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
				End If

				tblToUsers.Visible = True
				ddlDirectFriends.Visible = False
				hlToName.Visible = True
				hlToPhoto.Visible = False
				hlToName.Text = grp.Name
				hlToName.NavigateUrl = "../" + Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID

				If grp.DefaultPicture <> Nothing Then
					' Init group image here
					hlToPhoto.ImageUrl = Pictures.GetPictureSrcFullURL(grp.DefaultPicture, True, "../")
					hlToPhoto.Visible = True
					hlToPhoto.NavigateUrl = "../" + Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID
					hlToPhoto.ToolTip = grp.Name
				End If
			End If

			' init message and body

			If Request.Params("id") <> Nothing Then
				Try
					msgID = Convert.ToInt32(Request.Params("id"))
					msgType = Convert.ToInt32(Request.Params(Constants.MSG_TYPE_PARAM))
					bIsGroupBulletin = (msgType = (DirectCast(Messages.MessageType.mtGroupBulletin, Integer)))
				Catch
					Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
				End Try

				Dim msg As Message = Nothing

				'if ( bIsGroupBulletin )
				'	msg = Messages.GetUserGroupBulletin(usr.ID, -1, msgID);
				'else
				'	msg = Messages.GetUserMessage(usr.ID, msgID);
				If isGroupMode Then
					If isUserMode Then
						msg = Messages.GetUserGroupBulletin(usr.ID, grpID, msgID)
					Else
						msg = Messages.GetGroupBulletin(grpID, msgID)
					End If
				Else
					If bIsGroupBulletin Then
						msg = Messages.GetUserGroupBulletin(usr.ID, -1, msgID)
					Else
						msg = Messages.GetUserMessage(usr.ID, msgID)
					End If
				End If

				If msg <> Nothing Then
					Select Case action
						Case Constants.MESSAGE_REPLY_ACTION
							txtSubject_bulletin.Text = "Re: " + msg.Subject
							txtMessage_bulletin.Text = "-- Original Message -- " + Environment.NewLine + "From: " + msg.Sender.Name + Environment.NewLine + "Date: " + msg.DateSent + Environment.NewLine + Environment.NewLine + msg.Body
							Exit Select
						Case Constants.MESSAGE_FORWARD_ACTION
							txtSubject_bulletin.Text = "Fwd: " + msg.Subject
							txtMessage_bulletin.Text = "-- Forwarded Message -- " + Environment.NewLine + "From: " + msg.Sender.Name + Environment.NewLine + "Date: " + msg.DateSent + Environment.NewLine + Environment.NewLine + msg.Body
							Exit Select
					End Select
				End If
			End If

			' init subject and body for "Forward a friend"
			If action = Constants.MESSAGE_FORWARD_A_FRIEND_ACTION Then
				Dim fuid As Integer = Convert.ToInt32(Request.Params(Constants.FORWARD_A_FRIEND_PARAM))

				If action = Constants.MESSAGE_FORWARD_A_FRIEND_ACTION Then
					If fuid = LoggedUser.ID Then
						lblSendYourselfMessage.Text = Me.GetPageConstText(htPageConstants, "CONST_MsgCannotForwardYou_TEXT")
						lblSendYourselfMessage.Visible = True
						HideAllFields()
					End If
				End If

				txtSubject_bulletin.Text = Constants.MESSAGE_FORWARD_A_FRIEND_SUBJECT
				txtMessage_bulletin.Text = Constants.MESSAGE_FORWARD_A_FRIEND_BODY + Environment.NewLine + Environment.NewLine + Constants.APPLICATION_URL + "/" + Constants.MEMBERS + "?id=" + fuid
			End If

			' init subject and body for "Recommend a match"
			If action = Constants.MESSAGE_RECOMMEND_ACTION Then
				Dim ruid As Integer = Convert.ToInt32(Request.Params(Constants.RECOMMENDED_USER_PARAM))
				Dim rtouid As Integer = Convert.ToInt32(Request.Params(Constants.RECOMMENDED_TO_USER_PARAM))
				txtSubject_bulletin.Text = Constants.MESSAGE_RECOMMEND_A_MATCH_SUBJECT.Replace(Constants.TXT_RECOMMENDED_FROM_TAG, LoggedUser.Name)

				Dim link1 As String = Constants.APPLICATION_URL + "/" + Constants.MEMBERS + "?id=" + ruid
				Dim link2 As String = Constants.APPLICATION_URL + "/" + Constants.MEMBERS + "?id=" + rtouid

				txtMessage_bulletin.Text = Constants.MESSAGE_RECOMMEND_A_MATCH_BODY.Replace(Constants.TXT_RECOMMENDED_FROM_TAG, LoggedUser.Name)
				txtMessage_bulletin.Text = txtMessage_bulletin.Text.Replace(Constants.TXT_RECOMMEND_A_MATCH_LINK1_TAG, link1)
				txtMessage_bulletin.Text = txtMessage_bulletin.Text.Replace(Constants.TXT_RECOMMEND_A_MATCH_LINK2_TAG, link2)
			End If

			' init subject and body for "Recommend a group"
			If action = Constants.MESSAGE_FORWARD_A_GROUP_ACTION Then
				Dim fgid As Integer = Convert.ToInt32(Request.Params(Constants.FORWARD_A_GROUP_PARAM))
				txtSubject_bulletin.Text = Constants.MESSAGE_FORWARD_A_GROUP_SUBJECT
				txtMessage_bulletin.Text = Constants.MESSAGE_FORWARD_A_GROUP_BODY + Environment.NewLine + Environment.NewLine + Constants.APPLICATION_URL + "/" + Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + fgid
				hlBackToInbox.NavigateUrl = "../" + Constants.GROUP_WELCOME + "?" + Constants.GROUP_PARAM + "=" + fgid
				hlBackToInbox.Text = Me.GetPageConstText(htPageConstants, "CONST_GroupReturn_TEXT")

				grp = Groups.GetGroupByID(fgid)
				If grp = Nothing Then
					Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
				End If
				hlBackToGroup.NavigateUrl = "../" + Constants.GROUP_WELCOME + "?" + Constants.GROUP_PARAM + "=" + fgid
				hlBackToGroup.Text = (Me.GetPageConstText(htPageConstants, "CONST_GroupBackLink_TEXT")).Replace("[PARAM]", grp.Name)
			End If
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()

		End Sub
#End Region

		Protected Sub btn_send_bulletin_Click(ByVal sender As Object, ByVal e As System.EventArgs)

			If Page.IsValid Then
				If LoggedUser = Nothing Then
					Common.Utils.RedirectToLoginPage(Page)
				End If
				Dim usrToID As Integer
				Dim isGroupSubject As Boolean = False
				Dim usrTo As User

				If action = Constants.MESSAGE_FORWARD_ACTION OrElse action = Constants.MESSAGE_FORWARD_A_FRIEND_ACTION OrElse action = Constants.MESSAGE_FORWARD_A_GROUP_ACTION Then
					usrToID = Convert.ToInt32(ddlDirectFriends.SelectedItem.Value)
ElseIf action = Constants.MESSAGE_TO_GROUP_ACTION Then
					If Not isGroupMode Then
						Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
					End If

					usrToID = grp.Uid
					isGroupSubject = True
				Else
					usrToID = Convert.ToInt32(Request.Params("uid"))
				End If

				usrTo = Users.GetUserByID(usrToID)
				usrID = usrToID
				ViewState("uid") = usrID
				If usrTo <> Nothing Then
					Dim subject As String = ""
					Dim body As String = ""

					If isGroupSubject Then
						If grp <> Nothing Then
							subject = " Group message from " + grp.Name + " group: " + Request.Params(txtSubject_bulletin.UniqueID).Trim()
						Else
							Throw New Exception(Constants.ERROR_MESSAGE_GROUP_DOESNT_EXIST_ERROR)
						End If
					Else
						subject = Request.Params(txtSubject_bulletin.UniqueID).Trim()
					End If

					body = Request.Params(txtMessage_bulletin.UniqueID).Trim()

					subject = removeScriptTags(subject.Substring(0, Math.Min(subject.Length, Constants.TEXT_FIELD_MESSAGES_SUBJECT_MAX_CHARS)))
					body = removeScriptTags(body.Substring(0, Math.Min(body.Length, Constants.TEXT_AREA_LONG_MESSAGES_MAX_CHARS)))

					If (action = Constants.MESSAGE_FORWARD_ACTION) OrElse (action = Constants.MESSAGE_FORWARD_A_FRIEND_ACTION) OrElse (action = Constants.MESSAGE_FORWARD_A_GROUP_ACTION) Then
						hlToNameConfirm.Text = Me.getBeginning(HttpUtility.HtmlEncode(usrTo.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
						hlToNameConfirm.NavigateUrl = "../" + Constants.MEMBERS + "?id=" + usrTo.ID
						hlToNameConfirm.Visible = True

						If usrTo.DefaultPicture <> Nothing Then
							hlToPhotoConfirm.ImageUrl = Pictures.GetPictureSrcFullURL(usrTo.DefaultPicture, True, "../")
							hlToPhotoConfirm.NavigateUrl = "../" + Constants.MEMBERS + "?id=" + usrTo.ID
							hlToPhotoConfirm.ToolTip = usrTo.Name
							hlToPhotoConfirm.Visible = True
						Else
							hlToPhotoConfirm.Visible = False
						End If
					Else
						hlToNameConfirm.Text = hlToName.Text
						hlToNameConfirm.NavigateUrl = hlToName.NavigateUrl
						hlToNameConfirm.Visible = hlToName.Visible

						hlToPhotoConfirm.ImageUrl = hlToPhoto.ImageUrl
						hlToPhotoConfirm.ToolTip = hlToPhoto.ToolTip
						hlToPhotoConfirm.Visible = hlToPhoto.Visible
						hlToPhotoConfirm.NavigateUrl = hlToPhoto.NavigateUrl

						hlTo2NameConfirm.Text = hlTo2Name.Text
						hlTo2NameConfirm.NavigateUrl = hlTo2Name.NavigateUrl
						hlTo2NameConfirm.Visible = hlTo2Name.Visible

						hlTo2PhotoConfirm.ToolTip = hlTo2Photo.ToolTip
						hlTo2PhotoConfirm.ImageUrl = hlTo2Photo.ImageUrl
						hlTo2PhotoConfirm.NavigateUrl = hlTo2Photo.NavigateUrl
						hlTo2PhotoConfirm.Visible = hlTo2Photo.Visible
					End If

					lblSubjectContentConfirm.Text = subject
					lblMessageContent.Text = showLinksInMessage(body, False)

					Dim bTbl As Boolean = tblToUsers.Visible
					trMessagePost.Visible = False
					trConfrimation.Visible = True

					If (action = Constants.MESSAGE_FORWARD_ACTION) OrElse (action = Constants.MESSAGE_FORWARD_A_FRIEND_ACTION) OrElse (action = Constants.MESSAGE_FORWARD_A_GROUP_ACTION) Then
						tblToUsersConfirm.Visible = Not bTbl
					Else
						tblToUsersConfirm.Visible = bTbl


						'				Message msgNew;
'
'									if ( action == Constants.MESSAGE_TO_GROUP_ACTION )
'									{
'										msgNew = new Message( LoggedUser.ID, grp.Uid, subject, body );
'										msgNew.SendGroupMessage();
'									}
'									else
'									{
'										msgNew = new Message( LoggedUser.ID, usrToID, subject, body );
'										msgNew.Send();					
'									}
'
'									if (action == Constants.MESSAGE_RECOMMEND_ACTION) 
'									{
'										int ruid = Convert.ToInt32(Request.Params[Constants.RECOMMENDED_USER_PARAM]);
'										usrTo = Users.GetUserByID(ruid);
'										if(usrTo != null)
'										{
'											msgNew = new Message( LoggedUser.ID, usrTo.ID, subject, body );
'											msgNew.Send();
'										}
'										else
'										{
'											throw new Exception (Constants.ERROR_MESSAGE_MISSING_PARAMETERS);
'										}
'									}
'									lblMessageSent.Visible = true;
'					
					End If
				Else
					Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
				End If
			End If
		End Sub



		Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			If Not trConfrimation.Visible Then
				If isGroupMode Then
					Response.Redirect(Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID)
				Else
					Response.Redirect(Constants.MEMBERS + "?id=" + usrID)
				End If
			Else
				trMessagePost.Visible = True
				trConfrimation.Visible = False
			End If
		End Sub

		Protected Sub btnPost_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			If usrID = -1 Then
				usrID = Convert.ToInt32(ViewState("uid").ToString())
			End If

			Dim usrTo As User = Users.GetUserByID(usrID)
			Dim loggedUsr As User = LoggedUser

			Dim subject As String = lblSubjectContentConfirm.Text
			Dim body As String = lblMessageContent.Text

			Dim msgNew As Message

			If action = Constants.MESSAGE_TO_GROUP_ACTION Then
				msgNew = New Message(LoggedUser.ID, grp.Uid, subject, body)
				msgNew.SendGroupMessage()
			Else
				msgNew = New Message(LoggedUser.ID, usrTo.ID, subject, body)
				msgNew.Send()
			End If

			If action = Constants.MESSAGE_RECOMMEND_ACTION Then
				Dim ruid As Integer = Convert.ToInt32(Request.Params(Constants.RECOMMENDED_USER_PARAM))
				usrTo = Users.GetUserByID(ruid)
				If usrTo <> Nothing Then
					msgNew = New Message(LoggedUser.ID, usrTo.ID, subject, body)
					msgNew.Send()
				Else
					Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
				End If
			End If

			trMessagePost.Visible = True
			trConfrimation.Visible = False

			lblMessageSent.Visible = True
		End Sub

		Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Dim subject As String = lblSubjectContentConfirm.Text
			Dim body As String = lblMessageContent.Text

			txtMessage_bulletin.Text = body
			txtSubject_bulletin.Text = subject

			trMessagePost.Visible = True
			trConfrimation.Visible = False
		End Sub

		Private Sub HideAllFields()
			lblTo.Visible = False
			ddlDirectFriends.Visible = False
			hlToName.Visible = False
			hlTo2Name.Visible = False
			hlToPhoto.Visible = False
			hlTo2Photo.Visible = False
			lblSubject.Visible = False
			txtSubject_bulletin.Visible = False
			rvSubject_bulletin.Visible = False
			lblMessage.Visible = False
			txtMessage_bulletin.Visible = False
			rvMessage_bulletin.Visible = False
			btn_send_bulletin.Visible = False
		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
		Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_Form1
			End Get
		End Property
		'set { Migrated_Form1 = value; }
	End Class

	' End of class


End Namespace






